package org.example;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Utils {
    public static boolean isNumber(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            boolean digit = Character.isDigit(str.charAt(i));
            if (!digit) {
                return false;
            }
        }
        return true;
    }


    public static List<byte[]> convert(Collection<?> collection, List<byte[]> list) throws SQLException {
        for (Object t : collection) {
            if (t == null) {
                list.add(null);
            } else if (t instanceof byte[]) {
                list.add((byte[]) t);
            } else if (t instanceof Collection) {
                List<byte[]> decode = convert((Collection<?>) t, new ArrayList<>());
                list.addAll(decode);
            } else {
                throw new SQLException("Cannot deserialize.");
            }
        }
        return list;
    }
}
